package com.youxin.busfoundation.bean.classify;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.youxin.busfoundation.bean.BaseRequestBean;

/**
 * 输出类别,区域id
 * @author yingde.cao
 *
 */
@JsonInclude( JsonInclude.Include.NON_NULL)
public class ResponseCityBean implements Serializable,Cloneable{
    /**
	 * 
	 */
	private static final long serialVersionUID = 193549290354903254L;
	/** 唯一ID */
	@JsonProperty("uid")
    private Integer regionId;
//id	region_id	region_name	parent_id	region_type	letter
    /** 行业名称 */
	@JsonProperty("name")
    private String regionName;

	@JsonProperty("pid")
    private Integer parentId;


    public Integer getRegionId() {
		return regionId;
	}

	public void setRegionId(Integer regionId) {
		this.regionId = regionId;
	}

	public String getRegionName() {
		return regionName;
	}

	public void setRegionName(String regionName) {
		this.regionName = regionName;
	}

	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	private List<ResponseCityBean> childs;

	public List<ResponseCityBean> getChilds() {
		
		return childs;
	}

	public void addChild(ResponseCityBean bean){
		if(childs==null){
			childs=new ArrayList<>(50);
		}
		childs.add(bean);
	}
    
	@JsonIgnore
    public boolean isTopLevel()
    {
    	return parentId.intValue()==1?true:false;
    }
    
	
    public boolean isChildInItem(ResponseCityBean topItem)
    {
    	return parentId.intValue()==topItem.getRegionId().intValue();
    }
    
    public ResponseCityBean isChildInItems(List<ResponseCityBean> topItems)
    {
    	for(ResponseCityBean item:topItems)
    	{
    		if(isChildInItem(item))
    		{
    			return item;
    		}
    	}
    	return null;
    }
    
    /* (non-Javadoc)
     * @see java.lang.Object#clone()
     */
    @Override
    public Object clone() throws CloneNotSupportedException {
    	// TODO Auto-generated method stub
    	return super.clone();
    }
    
//    @Override
//    public int hashCode() {
//    	// TODO Auto-generated method stub
//    	return regionId.hashCode();
//    }
//    
//    @Override
//    public boolean equals(Object obj) {
//    	if(obj instanceof ResponseCityBean){
//    		return ((ResponseCityBean)obj).getRegionId().equals(regionId);
//    	}
//    	return false;
//    }
   
}
